package com.netitv.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

import com.netitv.domain.AdministratorInfo;
import com.netitv.domain.dayClick;

public class DayClickDaoImpl extends JdbcDaoSupport implements
		com.netitv.dao.DayClickDao {

	@Override
	public int addDayClick(dayClick daycclik) {
		int i = 0;
		String sql = "insert into dayclick(clickTime,userID,isplay,channelid,filmid,userFrom) values(?,?,?,?,?,?)";
		i = this.getJdbcTemplate().update(
				sql,
				new Object[] { daycclik.getClickTime(), daycclik.getUserID(),
						daycclik.getIsplay(), daycclik.getChannelid(),
						daycclik.getFilmid(),daycclik.getUserFrom() });
		return i;
	}

	@Override
	public List<dayClick> finByTime(Date time) {
		// TODO Auto-generated method stub
		String sql = "select * from dayclick where clickTime like %?%";

		List<dayClick> test = this.getJdbcTemplate().query(sql,
				new Object[] { time }, new dayClickMapper());
		return test;
	}

	protected class dayClickMapper implements RowMapper {
		public dayClick mapRow(ResultSet rs, int rowNum) throws SQLException {
			dayClick dayClick = new dayClick();
			dayClick.setId(rs.getInt("id"));
			dayClick.setUserID(rs.getString("userIP"));
			dayClick.setClickTime(rs.getDate("clickTime"));
			dayClick.setIsplay(rs.getInt("isplay"));
			dayClick.setChannelid(rs.getInt("channelid"));
			dayClick.setFilmid(rs.getInt("filmid"));
			dayClick.setUserFrom(rs.getString("userFrom"));
			return dayClick;
		}
	}

}
